<%@include file="/jsp/import.jspf" %>
<%@include file="/jsp/taglib.jspf" %>
<%
            BaseHibernateDAO baseHibernateDAO = new BaseHibernateDAO();
            String query = request.getParameter(RequestConstant.QUERY);
            String param = request.getParameter("?q");
            String queryString = null;
            if (CommonUtil.isNotEmpty(query)) {
                queryString = QueryUtil.getQuery(query, param, request.getParameterMap());
            } else {
                String column = request.getParameter(RequestConstant.COLUMN);
                String columns = request.getParameter(RequestConstant.COLUMNS);
                columns = CommonUtil.isNotEmpty(columns) ? column + "," + columns : column;
                String table = request.getParameter(RequestConstant.TABLE);
                queryString = "SELECT DISTINCT " + columns + " FROM " + table + " WHERE " + column + " LIKE '" + param + "%' limit 10 ";
            }
            //queryString = ""; 
            String template = request.getParameter("template");
            List list = baseHibernateDAO.executeSQLQuery(queryString);
            if (CommonUtil.isNotEmpty(list)) {
                request.setAttribute("list", list);
                Object row = list.get(0);
                request.setAttribute("isString", row instanceof String);
                request.setAttribute("template", template);
            }
%>

<c:choose>
    <c:when test="${isString}">
        <c:forEach var="fieldValue" items="${list}">
            <li id="${fieldValue}">
                <font color="#093ba1"> ${fieldValue} </font>
            </li>
        </c:forEach>
    </c:when>
    <c:otherwise>
        <c:forEach var="row" items="${list}">
            <c:set var="fieldValues" value=""/>
            <c:forEach var="col" items="${row}">
                <c:set var="fieldValues" value="${fieldValues}${col}|"/>
            </c:forEach>
            <li id="${fieldValues}">
                <c:set var="values" value="${row}" scope="request"/>
                <c:choose>
                    <c:when test="${template=='client'}">
                        <%@include file="template/client.jsp"%>
                    </c:when>
                    <c:when test="${template=='trucker'}">
                        <%@include file="template/trucker.jsp"%>
                    </c:when>
                    <c:when test="${template=='ports'}">
                        <%@include file="template/ports.jsp"%>
                    </c:when>
                    <c:when test="${template=='city'}">
                        <%@include file="template/city.jsp"%>
                    </c:when>
                    <c:when test="${template=='filenumber'}">
                        <%@include file="template/filenumber.jsp"%>
                    </c:when>
                    <c:otherwise>
                        <%@include file="template/default.jsp"%>
                    </c:otherwise>
                </c:choose>
            </li>
        </c:forEach>
    </c:otherwise>
</c:choose>